
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/29/2012 13:19:05
-- Generated from EDMX file: C:\Users\MMR\Documents\Visual Studio 2010\Projects\SydEnergiDataService\AsyncDBClient\SydEnergiDb.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SydEnergiDb];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CabinetAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Cabinets] DROP CONSTRAINT [FK_CabinetAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_CabinetEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Entries] DROP CONSTRAINT [FK_CabinetEntry];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Addresses]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Addresses];
GO
IF OBJECT_ID(N'[dbo].[Cabinets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cabinets];
GO
IF OBJECT_ID(N'[dbo].[Entries]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Entries];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Addresses'
CREATE TABLE [dbo].[Addresses] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [StreetName] nvarchar(max)  NOT NULL,
    [StreetNumber] int  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [ZipCode] int  NOT NULL,
    [Floor] nvarchar(max)  NULL,
    [StairCasePosition] nvarchar(max)  NULL,
    [Letter] nvarchar(max)  NULL
);
GO

-- Creating table 'Cabinets'
CREATE TABLE [dbo].[Cabinets] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CabinetId] nvarchar(max)  NOT NULL,
    [Latitude] float  NOT NULL,
    [Longitude] float  NOT NULL,
    [Address_Id] int  NOT NULL
);
GO

-- Creating table 'Entries'
CREATE TABLE [dbo].[Entries] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Tube] nvarchar(max)  NOT NULL,
    [Fiber] nvarchar(max)  NOT NULL,
    [CabinetId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Addresses'
ALTER TABLE [dbo].[Addresses]
ADD CONSTRAINT [PK_Addresses]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Cabinets'
ALTER TABLE [dbo].[Cabinets]
ADD CONSTRAINT [PK_Cabinets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Entries'
ALTER TABLE [dbo].[Entries]
ADD CONSTRAINT [PK_Entries]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Address_Id] in table 'Cabinets'
ALTER TABLE [dbo].[Cabinets]
ADD CONSTRAINT [FK_CabinetAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CabinetAddress'
CREATE INDEX [IX_FK_CabinetAddress]
ON [dbo].[Cabinets]
    ([Address_Id]);
GO

-- Creating foreign key on [CabinetId] in table 'Entries'
ALTER TABLE [dbo].[Entries]
ADD CONSTRAINT [FK_CabinetEntry]
    FOREIGN KEY ([CabinetId])
    REFERENCES [dbo].[Cabinets]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CabinetEntry'
CREATE INDEX [IX_FK_CabinetEntry]
ON [dbo].[Entries]
    ([CabinetId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------